<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>demo</title>
  <script type="text/javascript" src="../vue.js"></script>
</head>

<body>
  <div id="app">
    <input type="" v-model="first">
    <input type="" v-model="last">
    <p>
      {{fullName}}
    </p>
    <button @click="update">获取姓名</button>
  </div>
</body>
<script type="text/javascript">
  Vue.config.productionTip = false
  const vm = new Vue({
    el: "#app",
    data() {
      return {
        first: '',
        last: ''
      }
    }
    , computed: {
      fullName: {
        get() {
          console.log('get方法被调用了');
          return this.first + this.last
        },
        set(value) {
          console.log(value, 'set方法被调用了');
          // 这里修改first和last的值
          [this.first, this.last] = value.split(' ')
        }
      }
    },
    methods: {
      update() {
        this.fullName = 'luo fei'
      }
    }
  })
</script>

</html>